package servlet.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pojo.Customer;
import service.CustomerManager;
import service.impl.CustomerManagerFactory;

public class LoginActionServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	private CustomerManager manager = CustomerManagerFactory.INSTANCE;

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String cname = request.getParameter("cname");
		String passwd = request.getParameter("passwd");
		Customer c = manager.login(cname, passwd);
		
		if (c == null) {
			response.sendRedirect("login");
		} else {
			request.getSession().setAttribute("customer", c);
			response.sendRedirect("sec/books");
		}
	}

}
